#pragma once
#include "cgzCTcpS.h"

using namespace boost::asio;
using ip::tcp;

class cgzCTcpAsioS;

class cgzSessionS : public cgzCTcpFd
{
public:
    friend class cgzCTcpAsioS;
    cgzSessionS(
        int fd,
        int ufd,
        tcp::socket socket,
        cgzCTcpAsioS *that);

public:
    void do_read();
    void do_send(cgzCSendS *send);
    tcp::socket m_socket;

private:
    cgzCTcpAsioS *m_that;
    std::string m_ip; 
    int m_port;
};

class cgzCTcpAsioS : public cgzCTcpS
{
public:
    cgzCTcpAsioS(cgzCThreadPool *pool,
                const char *name,
                const std::string ip,
                const int port,
                const int cid);

    virtual ~cgzCTcpAsioS();

public:
    bool tcpbind() override;
    bool tcpread() override;
    bool tcpsend() override;
    bool taccpet() override;

private:
    void do_accept();
    void do_tgoing();

private:
    // tcp socket
    io_context* m_iocontext;
    ip::tcp::acceptor* m_acceptor;
};
